home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / SPPC / ShowINIT.a < prev    next >
Text File  |  1988-08-07  |  10KB  |  323 lines

  1. ; File: ShowINIT.a
  2. ; Last Modified: Friday, July 15, 1988 12:08:09 AM
  3. ;------------------------------------------------------------------------------------------------
  4. ;
  5. ;    INIT notification routine
  6. ;     by Paul Mercer, Darin Adler, and Paul Snively from an idea by Steve Capps
  7. ;
  8. ;    Created:  6/7/87  PM    - First version.
  9. ;    Modified: 6/15/87 PM    - Changed to standard (Pascal) calling conventions.
  10. ;          6/20/87 PM    - Fixed color & Finder bug on Mac II.
  11. ;          6/22/87 DBA    - Improved handling of QuickDraw.
  12. ;          6/29/87 DBA    - Used scratch8 to avoid conflict with “Easy Access”.
  13. ;          6/30/87 DBA    - Changed to a 4-byte scheme with “checksum”.
  14. ;          6/30/87 PFS    - Separated into ShowINIT and InnerShowINIT.
  15. ;          7/1/87  DBA    - Fixed stack bug and switched to CurApName+.
  16. ;          7/2/87  PM    - Added check for old signature in ApplScratch for
  17. ;                   backword compatibility (TMON Startup).
  18. ;          7/3/87  PM    - Removed _SysBeep in ErrorExit since it causes a crash.
  19. ;                   Also changed ICN# plotter to srcOr mode for Blinker.
  20. ;          7/13/87 PM    - Fixed a3 trashing bug in InnerShowINIT - exit code left
  21. ;                   word on stack (reported by D. Dunham). 
  22. ;          7/21/87 PM    - Due to popular demand, InitGraf is no longer being called.
  23. ;                   This avoids the gamma correction problem with Startupscreens
  24. ;                   getting  “washed out” by ShowINIT though someone else is still
  25. ;                   bound to call InitGraf sooner or later (i.e. InitWindows).
  26. ;          7/29/87 PM    - Put InitGraf back in; this is required (reported by C. Derossi
  27. ;                   at Apple Tech Support).  Took out GetPort/SetPort.
  28. ;        10/06/87  PM    - Set CurrentA5 properly.  Rearranged myVars.
  29. ;        12/28/87  PM    - Major revision to accomodate future INIT31 based ShowINIT.
  30. ;        07/14/88  PM    - Major revision to get rid of above 'accomodations'.
  31. ;                   Added color icon 'cicn' support and fixed beep crash.
  32. ;                   Removed support for old signature.
  33. ;        
  34. ;------------------------------------------------------------------------------------------------
  35.  
  36.         INCLUDE    'Traps.a'
  37.         INCLUDE    'QuickEqu.a'
  38.         INCLUDE    'SysEqu.a'
  39.         INCLUDE    'ToolEqu.a'
  40.  
  41.         BLANKS  ON
  42.         STRING  ASIS
  43.  
  44. True        equ    1
  45. False        equ    0
  46.  
  47. Debug        equ    True
  48. ;Debug        equ    False
  49.  
  50. myH        equ    CurApName+32-4        ; a GREAT place to store 4 bytes (it was Darin's idea)
  51. myCheck        equ    myH+2            ; a simple checksum of myH to determine first-timeness
  52. firstX        equ    8            ; X coordinate of first icon to be drawn
  53. bottomEdge    equ    8+32            ; this far from bottom of screen
  54. iconWidth    equ    32            ; size of icon (square normally)
  55. defaultMoveX    equ    40            ; default amount to move icons
  56. checksumConst    equ    $1021            ; constant used for computing checksum
  57. minColorDepth    equ    4            ; minimum bits/pixel for drawing color icons
  58.  
  59. maskOffset    equ    128            ; offset to mask in ICN#
  60. iconRowBytes    equ    32/8            ; 32/8 bits
  61.  
  62. hasCQDBit    equ    6            ; this bit in ROM85 is cleared if Color QuickDraw is available
  63.  
  64. iconID        equ    6+4            ; positive stackframe objects
  65. moveX        equ    4+4
  66. showINITArgs    equ    4
  67. iconPtrHdl    equ    6+4
  68. initDrawArgs    equ    6
  69.  
  70. myVars        RECORD    0,DECREMENT
  71. saveA5        ds.l    1
  72. localA5        ds.l    1
  73. thePort        ds.l    1            ; my own QuickDraw (required!)
  74.         ds.b    grafSize-4        ;  other QuickDraw globals (except thePort)
  75. destRect    ds.w    4
  76. myBitMap    ds.b    bitMapRec
  77. myPort        ds.b    portRec
  78. varsSize    equ    *
  79.         ENDR
  80.  
  81.  
  82. ;------------------------------------------------------------------------------------------------
  83. ;                                
  84. ;    Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID and
  85. ;     move the pen horizontally by moveX.
  86. ;    Pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  87. ;
  88. ;    PROCEDURE ShowINIT(iconID: Integer; moveX: Integer); EXTERNAL
  89. ;
  90. ;    pascal void ShowINIT(iconID, moveX)
  91. ;        short iconID, moveX;
  92. ;        extern;
  93. ;
  94. ;------------------------------------------------------------------------------------------------
  95. ShowINIT:    PROC    EXPORT
  96.         IMPORT    INITDraw1Bit, INITDrawCQD
  97.  
  98.         link    a6,#0            ; create stack frame
  99.         movem.l    d3-d7/a2-a4,-(sp)    ; save standard registers
  100.  
  101.         btst.b    #hasCQDBit,ROM85    ; try to get a color icon if CQD exists
  102.         beq.s    ShowINITCQD        ; I could use SysEnvirons but I don't want to
  103. ShowINIT1Bit
  104.         clr.l    -(sp)            ; try to get the icon resource
  105.         move.l    #'ICN#',-(sp)
  106.         move.w    iconID(a6),-(sp)
  107.         _GetResource
  108.         move.l    (sp)+,d0
  109.         beq.s    ShowINITError        ; can't get it, give up
  110.  
  111.         move.l    d0,-(sp)        ; leave handle on the stack for ReleaseResource
  112.         move.l    d0,a0
  113.         move.l    (a0),a0            ; dereference
  114.         move.l    a0,-(sp)        ; icon pointer
  115.         move.w    moveX(a6),-(sp)        ; moveX
  116.         bsr    INITDraw1Bit        ; draw
  117.         _ReleaseResource        ; releaese the resource
  118.  
  119. ShowINITExit:
  120.         movem.l    (sp)+,d3-d7/a2-a4    ; restore registers
  121.         unlk    a6            ; ditch stack frame
  122.         move.l    (sp)+,a0        ; get return address
  123.         addq.l    #showINITArgs,sp    ; ditch incoming arguments
  124.         jmp    (a0)            ; return to caller
  125.  
  126. ShowINITError:
  127.         IF    Debug THEN
  128.         move.w    #1,-(sp)        ; just beep
  129.         _SysBeep
  130.         ENDIF
  131.         bra.s    ShowINITExit
  132.  
  133.  
  134. ShowINITCQD:
  135.         move.l    MainDevice,a0        ; get handle to main device
  136.         move.l    (a0),a0            ; dereference
  137.         move.l    gdPMap(a0),a0        ; get its pixmap handle
  138.         move.l    (a0),a0            ; dereference it
  139.         cmp.w    #minColorDepth,pmPixelSize(a0)    ; is it deep enough for us to draw in color?
  140.         blt.s    ShowINIT1Bit            ;  no
  141.  
  142.         clr.l    -(sp)            ; can a color icon be found?
  143.         move.w    iconID(a6),-(sp)
  144.         _GetCIcon
  145.         move.l    (sp)+,d0
  146.         beq.s    ShowINIT1Bit        ;  no, so try for regular icon
  147.  
  148.         move.l    d0,-(sp)        ; leave handle on the stack for DisposCIcon
  149.         move.l    d0,-(sp)        ; cicn handle
  150.         move.w    moveX(a6),-(sp)        ; moveX
  151.         bsr    INITDrawCQD        ; do the actual drawing
  152.         _DisposCIcon
  153.  
  154.         bra.s    ShowINITExit
  155.  
  156.  
  157. ShowINITCredits:
  158.         dc.w    'ShowINIT by Paul Mercer'
  159.         dc.w    'Copyright 1987-1988'
  160.         dc.w    'Version of 7/15/88'
  161.         ENDPROC
  162.  
  163.  
  164. ;------------------------------------------------------------------------------------------------
  165. ;
  166. ;    Initializes the world and sets up the drawing rectangle
  167. ;
  168. ;------------------------------------------------------------------------------------------------
  169. INITInit:    PROC    EXPORT
  170.         WITH    myVars
  171.  
  172.         move.l    CurrentA5,saveA5(a6)    ; PM 10/6 save host A5
  173.         lea    localA5(a6),a5        ; PM7/21
  174.         move.l    a5,CurrentA5
  175.         pea    thePort(a6)        ; PM 10/6 use a5 reference instead of a6
  176.         _InitGraf            ; fixes color bug as per DA@ICOM
  177.         pea    myPort(a6)
  178.         _OpenPort
  179.  
  180.         move.w    myH,d0            ; get my h var
  181.         rol.w    #1,d0            ; compare against checksum
  182.         eor.w    #checksumConst,d0
  183.         cmp.w    myCheck,d0
  184.         beq.s    ScratchOK        ; checks, so go on
  185.         move    #firstX,myH        ; else initialize as first time
  186. ScratchOK:
  187.         lea    myPort(a6),a0        ; compute the destination rectangle
  188.         move.w    portBounds+bottom(a0),d0
  189.         sub.w    #bottomEdge,d0
  190.         swap    d0
  191.         move.w    myH,d0
  192.  
  193.         move.l    d0,destRect(a6)
  194.         move.l    d0,destRect+botRight(a6)
  195.         add.w    #iconWidth,destRect+right(a6)
  196.         add.w    #iconWidth,destRect+bottom(a6)
  197.  
  198.         rts
  199.  
  200.         ENDWITH
  201.         ENDPROC
  202.  
  203.  
  204. ;------------------------------------------------------------------------------------------------
  205. ;
  206. ;    Cleans up the work done by INITInit and advances the icon drawing position
  207. ;
  208. ;------------------------------------------------------------------------------------------------
  209. INITCleanup:    PROC    EXPORT
  210.         WITH    myVars
  211.  
  212.         move.w    myH,d0            ; get current position
  213.         move.w    moveX(a6),d1        ; get delta x
  214.         bpl.s    NotDefault        ; not default (-1)
  215.         move.w    #defaultMoveX,d1    ; default
  216. NotDefault:
  217.         add.w    d1,d0            ; increment icon position
  218.         move.w    d0,myH            ;  and save in ‘global’
  219.         rol.w    #1,d0            ; recompute checksum
  220.         eor.w    #checksumConst,d0
  221.         move.w    d0,myCheck        ;  and save it
  222. Exit:
  223.         pea    myPort(a6)
  224.         _ClosePort
  225.         ; *** (DBA) I think that QuickDraw leaves handles around.
  226.         ; *** (DBA) Too bad we can't get rid of them...
  227.         move.l    saveA5(a6),a5        ; PM 10/6 restore host A5
  228.         move.l    a5,CurrentA5
  229.         rts
  230.  
  231.         ENDWITH
  232.         ENDPROC
  233.  
  234.  
  235. ;------------------------------------------------------------------------------------------------
  236. ;                                
  237. ;    display the ICN# pointed to by iconPtr and move the pen horizontally by moveX
  238. ;     pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  239. ;
  240. ;    PROCEDURE INITDraw1Bit(iconPtr: ICONListPtr; moveX: Integer); EXTERNAL
  241. ;
  242. ;    pascal void INITDraw1Bit(iconPtr, moveX)
  243. ;        ICONList *iconPtr;
  244. ;        short moveX;
  245. ;        extern;
  246. ;
  247. ;------------------------------------------------------------------------------------------------
  248. INITDraw1Bit:    PROC    EXPORT
  249.         IMPORT    INITInit, INITCleanup:CODE
  250.         WITH    myVars
  251.  
  252.         link    a6,#varsSize        ; create stack frame
  253.         movem.l    d3-d7/a2-a4,-(sp)    ; save standard registers
  254.         bsr    INITInit        ; initialize for drawing
  255.  
  256.         move.l    iconPtrHdl(a6),a3    ; get ICN# pointer
  257.         lea    myBitMap(a6),a4        ; point to bitmap structure
  258.         move.l    a3,baseAddr(a4)        ; fill it out
  259.         add.l    #maskOffset,baseAddr(a4) ; skip to mask
  260.         move    #iconRowBytes,rowBytes(a4)
  261.         move.l    #0,bounds(a4)        ; 0,0 topleft
  262.         move.w    #iconWidth,bounds+bottom(a4) ; 32,32 botright
  263.         move.w    #iconWidth,bounds+right(a4)
  264.  
  265.         move.l    a4,-(sp)        ; punch hole with mask
  266.         lea    myPort(a6),a2        ; get the desk port
  267.         pea    portBits(a2)        ;  for its portbits
  268.         pea    srcRect
  269.         pea    destRect(a6)
  270.         move    #srcBic,-(sp)        ; punch a hole
  271.         clr.l    -(sp)            ; no clip region
  272.         _CopyBits
  273.  
  274.         sub.l    #128,baseAddr(a4)
  275.         move.l    a4,-(sp)        ; now draw (or) icon
  276.         pea    portBits(a2)
  277.         pea    srcRect
  278.         pea    destRect(a6)
  279.         move    #srcOr,-(sp)
  280.         clr.l    -(sp)
  281.         _CopyBits
  282.  
  283.         bsr    INITCleanup        ; cleanup, advance icon location
  284.         movem.l    (sp)+,d3-d7/a2-a4    ; restore registers
  285.         unlk    a6            ; ditch stack frame
  286.         move.l    (sp)+,a0        ; get return address
  287.         addq.l    #initDrawArgs,sp    ; ditch incoming
  288.         jmp    (a0)            ; back to caller
  289.  
  290. srcRect:    dc.w    0,0,32,32        ; for copybits
  291.  
  292.         ENDWITH
  293.         ENDPROC
  294.  
  295.  
  296. ;------------------------------------------------------------------------------------------------
  297. ;    same as above except with color icon handle
  298. ;------------------------------------------------------------------------------------------------
  299. INITDrawCQD:    PROC    EXPORT
  300.         IMPORT    INITInit, INITCleanup:CODE
  301.         WITH    myVars
  302.  
  303.         link    a6,#varsSize        ; create stack frame
  304.         movem.l    d3-d7/a2-a4,-(sp)    ; save standard registers
  305.         bsr    INITInit        ; initialize for drawing
  306.  
  307.         pea    destRect(a6)        ; destination rect
  308.         move.l    iconPtrHdl(a6),-(sp)    ; cicn handle
  309.         _PlotCIcon            ; draw it
  310.  
  311.         bsr    INITCleanup        ; cleanup, advance icon location
  312.         movem.l    (sp)+,d3-d7/a2-a4    ; restore registers
  313.         unlk    a6            ; ditch stack frame
  314.         move.l    (sp)+,a0        ; get return address
  315.         addq.l    #initDrawArgs,sp    ; ditch incoming
  316.         jmp    (a0)            ; back to caller
  317.  
  318.         ENDWITH
  319.         ENDPROC
  320.  
  321.  
  322.         END
  323.